define(function(require,exports,module){
	require('masonry');
	exports.init = function(){
		//瀑布流效果
		masonry_list();
		//鼠标hover商品上的放大效果
		mouse_hover_food();
	}	

	exports.operate = function(){

	}	
	exports.win_resize = function(){
		
	}

	function mouse_hover_food(){
		$(".cookbook_item").live('mouseenter',function(){
			var left = parseInt($(this).css("left"));
			var top = parseInt($(this).css("top"));
			$(this).css("height","240px");
			$(this).css("top",top-10 + "px");
			$(this).find(".food_operate").show();
			$(this).find(".food_info").show();
		}).live("mouseleave",function(){
			var top = parseInt($(this).css("top"));
			$(this).css("height","150px");
			$(this).css("top",top+10 + "px");
			$(this).find(".food_operate").hide();
			$(this).find(".food_info").hide();
		});
	}

	function masonry_list(){
		var food_container = $('#food_container');
		food_container.masonry({
		    itemSelector : '.cookbook_item',
		    isAnimated: true
		});
		var loading = $("#loading").data("on", false);
		$(window).scroll(function(){
		    if(loading.data("on")) return;
		    //注释：scrollTop:比如说上下的滚动条，当滚动条下拉是，上面隐藏的部分问scrollTop
		    //$(document).height()：整个文档的高度
		    //$(window).height()：可是区域的高度
		    //$('.footer').height()：底部元素的高度
		    if($(document).scrollTop() > $(document).height()-$(window).height()-$('.footer').height()){//页面拖到底部了
		        //加载更多数据
		        loading.data("on", true).fadeIn();         //在这里将on设为true来阻止继续的ajax请求
		        var to_data ={
		        	'pageNum':loading.find('span').attr('page_num')
		        }
		        // alert(loading.find('span').attr('page_num'))
		        $.get(
		            url.masonry_url, 
		            to_data,
		            function(data){
		            	if(!data.status){
		            		loading.remove();
		            		return;
		            	}
		               //获取到了数据data,后面用JS将数据新增到页面上
		                var html = "";
		                var cook_data = data.data.data;
		                if($.isArray(cook_data)){
		                	loading.find('span').attr('page_num',data.data.pageNum);
		                	for (var i = cook_data.length - 1; i >= 0; i--) {
		                		html += " <div class='cookbook_item'><a href='"+url.detail_url+cook_data[i]['cookbook_id']+"'><img class='list_pic_show' src='"+data.data.dir+cook_data[i]['cookbook_photo']+"' alt='"+cook_data[i]['cookbook_name']+"' title='"+cook_data[i]['cookbook_name']+"'></a><div class='food_info'><a href='"+url.detail_url+cook_data[i]['cookbook_id']+"'><span>"+cook_data[i]['cookbook_description']+"</span></a></div></div>";
		                	};

		                    var $newElems = $(html).css({ opacity: 0 }).appendTo(food_container);
	                        $newElems.animate({ opacity: 1 });
	                        food_container.masonry( 'appended', $newElems, true ); 
		                         
		                  //一次请求完成，将on设为false，可以进行下一次的请求
		                    loading.data("on", false);
		                }
		                loading.fadeOut();
		            },"json");
		    }
    	});		
	}
});